﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Hashtable hashtable = new Hashtable();
            hashtable.Add(1, "发噶哈");
            hashtable.Add(2, "法规及");
            hashtable.Add(3, "阿斯弗");
            foreach (DictionaryEntry item in hashtable)
            {
                var a = item.Key;
                var b = item.Value;
                Console.WriteLine("{0}{1}", a, b);
            }

            Console.WriteLine();

            Hashtable test = new Hashtable();
            test.Add(1,"小猫");
            test.Add(2,"小狗");
            test.Add(3,"猴子");
            test.Add(4,"大象");
            test.Add(5,"狮子");
            test.Add(6,"老虎");
            Console.WriteLine("你喜欢编号为几的动物");
            int number = int.Parse(Console.ReadLine()); //转换
            bool animal = test.ContainsKey(number); // 判断是否包含指定的键名
            if (animal)
            {
                Console.WriteLine("你喜欢的动物名为：{0}",test[number].ToString());
            }
            else
            {
                Console.WriteLine("没有这个动物");
            }
            Console.WriteLine("以下为已有动物");
            foreach (DictionaryEntry item1 in test)
            {
                var a = item1.Key;
                var b = item1.Value;
                Console.WriteLine("动物编号：{0}，动物名称：{1}", a, b);
            }
        }
    }
}
